﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="ViewTopic.aspx.cs" Inherits="LizzabethBrownRealEstate.Views.Users.ViewTopic" %>
<%@ Import Namespace="LizzabethBrownRealEstate.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<% LBRDataContext dc = new LBRDataContext(); %>
<div >
    <% Topic t = dc.GetTopic(int.Parse(ViewData["TopicId"].ToString())); %>
    <%if (t == null) t = new Topic(); %>
    <div class="CategoryDiv">Category:&nbsp;<%= t.Category == null ? "Category Not Found" : t.Category.Name %></div>
    <div class="MessageBoardSeparator">&nbsp;</div>
    <div class="TopicDiv">
        <div class="TopicTitle"><%= t.Title==null ? "Topic Not Found" : t.Title %></div>
        <%if (t.TopicId > 0)
          { 
         object topicId = new { topicId = t.TopicId.ToString() }; %>
        <%=Html.ActionLink("Add Reply", "Reply", "Users", topicId, null)%>
        <%} %>
    </div>
    <div class="MessageBoardSeparator">&nbsp;</div>
    
    <table class="MessageBoard">
        <% foreach (Message m in dc.GetMessagesByTopic(t.TopicId)) { %>
        <% object messageId = new {messageId = m.MessageId}; %>
        <tr class="MessageRow">
            <td class="MessageText"><%= m.MessageText %></td> 
            <td class="MessageDate"><%=m.CreateDate %></td>
            <% if (Roles.IsUserInRole("Administrator"))
               { %>
               <% object userId = new { userId = m.UserId.ToString() }; %>
                <td class="MessageUser"><%= Html.ActionLink(dc.GetUser(m.UserId.ToString()).UserName, "EditUser", "Admin", userId)%></td>
            <%}
               else
               { %>
                <td class="MessageUser"><%=dc.GetUser(m.UserId.ToString()).UserName%></td>
            <%} %>
        </tr>
        <%} %>
    </table>
</div>
</asp:Content>
